package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import anuncio.Anuncio;
import anuncio.ControlAnuncio;

/**
 * Servlet implementation class ServletAnuncioEspecifico
 */
public class ServletAnuncioEspecifico extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletAnuncioEspecifico() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Anuncio anun = new Anuncio();
		int cod = Integer.parseInt(request.getParameter("cod"));
		
		ControlAnuncio ca = new ControlAnuncio();
		anun = ca.pesquisa(cod);
		
		HttpSession session = request.getSession();
		session.setAttribute("listaesp", anun);
		response.sendRedirect("AnuncioEspecifico.jsp?id=" + anun.getId_anuncio() + "&cidade=" + anun.getCidade() + "&titulo=" + anun.getTitulo()
				+ "&desc=" + anun.getDesc_anuncio() + "&estado=" + anun.getEstado()+ "&valor=" + anun.getValoranuncio());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
